package com.ctshk.sapp.bus.controller;

import java.util.List;

import javax.validation.Valid;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.req.MainData;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.bus.dto.BusLineDTO;
import com.ctshk.rpc.bus.dto.BusLineListDTO;
import com.ctshk.rpc.bus.req.BusArriveCityListByLineQueryReq;
import com.ctshk.rpc.bus.req.BusDepartureCityListByLineQueryReq;
import com.ctshk.rpc.bus.req.BusLinePageReq;
import com.ctshk.rpc.bus.req.BusLineQueryReq;
import com.ctshk.rpc.bus.req.BusLineReq;
import com.ctshk.rpc.bus.req.BusStopsListByLineQueryReq;
import com.ctshk.rpc.bus.service.IBusLineService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 巴士线路管理 前端控制器
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-02-08
 */
@Api(value="资源中心-巴士线路管理", tags="资源中心-巴士线路管理")
@RestController
@RequestMapping("/bus-line")
public class BusLineController extends BaseController {

    @DubboReference
    private IBusLineService busLineService;

    @ApiOperation(value="巴士线路分页查询列表", notes="巴士线路分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "巴士线路列表", operDesc = "巴士线路列表")
    @PostMapping("/list")
    public Result<PageResponse<BusLineListDTO>> queryBusLineList(@RequestBody BusLinePageReq busLineListReq) {
        PageResponse<BusLineListDTO> response = busLineService.queyList(busLineListReq);
        return Result.success(response);
    }

    @ApiOperation(value="新增巴士路线", notes="新增巴士路线")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增巴士路线", operDesc = "新增巴士路线")
    @PostMapping("/save")
    public Result saveBusLine(@RequestBody @Valid BusLineReq busLineReq) {
        TokenUser user = getCurrentUser(getRequest());
        return busLineService.saveBusLine(busLineReq,user);
    }

    @ApiOperation(value="修改巴士路线", notes="修改巴士路线")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改巴士路线", operDesc = "修改巴士路线")
    @PostMapping("/update")
    public Result updateBusLine(@RequestBody @Valid BusLineReq busLineReq) {
        TokenUser user = getCurrentUser(getRequest());
        return busLineService.updateBusLine(busLineReq,user);
    }

    @ApiOperation(value = "查询巴士路线详情", notes = "查询巴士路线详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "编辑时查询巴士路线详情", operDesc = "编辑时查询巴士路线详情")
    @GetMapping(value = "/detail")
    public Result<BusLineDTO> queryDetail(@RequestParam(value = "id", required = true) Long id) {
        return Result.success(busLineService.queryDetail(id));
    }

    @ApiOperation(value = "巴士线路有效无效设置", notes = "巴士线路有效无效设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "巴士线路有效无效设置", operDesc = "巴士线路有效无效设置")
    @GetMapping("/isValid/{id}")
    public Result isValid(@PathVariable("id") Long id) {
        TokenUser user = getCurrentUser(getRequest());
        return busLineService.isValid(id,user);
    }


    @ApiOperation(value = "根据巴士公司查询巴士路线", notes = "根据巴士公司查询巴士路线")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据巴士公司查询巴士路线", operDesc = "根据巴士公司查询巴士路线")
    @PostMapping(value = "/queryLine")
    public Result<List<BusLineDTO>> queryLine(@RequestBody @Valid BusLineQueryReq busLineQueryReq) {
        return Result.success(busLineService.queryBusLine(busLineQueryReq));

    }

    @ApiOperation(value = "中港通巴士线路信息导入", notes = "中港通巴士线路信息导入")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "中港通巴士线路信息导入", operDesc = "中港通巴士线路信息导入")
    @GetMapping(value = "/hktBusLine/import")
    public Result importHktBusLine() {
        TokenUser user = getCurrentUser(getRequest());
        return busLineService.importHktBusLine(user);

    }

    @ApiOperation("查询巴士线路的出发城市列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询巴士线路的出发城市列表", operDesc = "查询巴士线路的出发城市列表")
    @PostMapping("queryDepartureCityListByLine")
    public Result<List<MainData>> queryDepartureCityListByLine(@RequestBody @Valid BusDepartureCityListByLineQueryReq req) {
    	return busLineService.queryDepartureCityListByLine(req);
    }
    
    @ApiOperation("查询巴士线路的到达城市列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询巴士线路的到达城市列表", operDesc = "查询巴士线路的到达城市列表")
    @PostMapping("queryArriveCityListByLine")
    public Result<List<MainData>> queryArriveCityListByLine(@RequestBody @Valid BusArriveCityListByLineQueryReq req) {
    	return busLineService.queryArriveCityListByLine(req);
    }
    
    @ApiOperation("查询巴士线路的站点列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询巴士线路的站点列表", operDesc = "查询巴士线路的站点列表")
    @PostMapping("queryStopsListByLine")
    public Result<List<MainData>> queryStopsListByLine(@RequestBody @Valid BusStopsListByLineQueryReq req) {
    	return busLineService.queryStopsListByLine(req);
    }
}
